该 综合 R 归档网络(CRAN) 是一个全球分布的集中式、同行评审服务器网络,托管超过 19,000 个包。它通过在多种硬件平台上严格的测试流程,确保了结构完整性。
1. 库与仓库的区别
区分两者至关重要: CRAN 是基于网页的 仓库 (源),而你的 库 是你本地磁盘上实际存放已安装包的目录。命令 library() 将已安装的代码加载到当前会话中。
2. 内省与原生资源
R 提供了工具来深入探究包的内部结构。 system.file() 用于获取包资源(如文档或数据集)的完整路径,而 file.show() 则用于显示这些资源。基础 R 默认包含 datasets 包,以及像 boot (用于自助法和统计重抽样)等“推荐”包。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
What is the technical difference between CRAN and a 'Library' in R?
CRAN is for documentation, Library is for code.
CRAN is the remote repository; Library is the local directory of installed packages.
They are synonymous terms for the search path.
Library is a sub-folder within the CRAN server.
✅ Correct!
Correct! You download from CRAN to your local Library.❌ Incorrect
CRAN acts as the global distribution network, whereas the Library is your local physical storage.QUESTION 2
Which function allows you to programmatically query all available tools on CRAN?
available.packages()installed.packages()show.cran()library(all)✅ Correct!
available.packages() (the successor to the CRAN.packages concept) queries the repository metadata.❌ Incorrect
installed.packages() only looks at your local disk; available.packages() queries the remote repository.QUESTION 3
What is the primary use of
system.file()?To delete temporary system files.
To find the physical file path of an installed package's assets.
To execute a system terminal command.
To download files from the internet.
✅ Correct!
It is an introspection tool that finds the full path to a file within a specific package.❌ Incorrect
It doesn't execute files; it finds their location on your hardware.QUESTION 4
Which of these packages is considered 'Recommended' and included by default in R distributions?
ggplot2tidyversebootshiny✅ Correct!
The boot package is part of the 'Recommended' tier, maintained alongside the core engine.❌ Incorrect
While popular, ggplot2 and tidyverse are third-party packages that must be explicitly installed.QUESTION 5
What does the
datasets package provide to the R ecosystem?A standard for SQL connectivity.
A collection of built-in data frames for testing and learning.
An interface for cloud storage.
Tools for data cleaning only.
✅ Correct!
It provides 'common language' data like mtcars and iris.❌ Incorrect
It is a repository of sample data frames, not a functional utility for cleaning or SQL.Case Study: Package Compliance Audit
Institutional Documentation Verification
A researcher needs to verify the version and license of the 'boot' package to ensure it meets institutional compliance before using it in a published clinical trial.
Q
What sequence of commands would locate and display the 'DESCRIPTION' file for the 'boot' package?
Solution:
First, load the package with
First, load the package with
library(boot). Then, locate the file path using path <- system.file('DESCRIPTION', package='boot')file.show(path).Q
Why is it better to use
system.file() rather than a hardcoded file path like 'C:/R/library/...'?Solution:
R libraries can be installed in different locations depending on the OS (Windows vs Mac) and user permissions.
R libraries can be installed in different locations depending on the OS (Windows vs Mac) and user permissions.
system.file() dynamically resolves the correct path regardless of the machine's configuration, ensuring code portability.